package com.cqcis.uip.base.framework.filters.adaptor;

import org.apache.mina.common.IoFilterAdapter;
import org.apache.mina.common.IoSession;

import com.cqcis.uip.base.framework.common.ControlMsg;
import com.cqcis.uip.base.framework.filters.FilterException;

public abstract class AbstractProtocolParseFilter extends IoFilterAdapter {
    
	/**
	 * XML文件解析 将XML文件转换成一个Map, (K - V) (包名 - 属性)	 */
	
	@Override
	public void messageReceived(NextFilter nextFilter, IoSession session, Object message) 
	             throws Exception {
		if (message instanceof ControlMsg) {
			nextFilter.messageReceived(session, message);
			return;
		}
		message = doMessageReceived(message);
		if (message == null) {
			throw new FilterException("Catch Exception in filter, the method of 'filter' can't return null.");
		}		
		
		nextFilter.messageReceived(session, message);
	}	
	
	/**
	 * 过滤接收到的数据
	 * @param message
	 * @return
	 * @throws Exception
	 */
	protected abstract Object doMessageReceived(Object message) throws Exception;
}
